home *** CD-ROM | disk | FTP | other *** search
/ Cracking 1 / Cracking I..iso / Tools / Ostatní / aPLib v0.26b / src / asm / depackf.asm < prev    next >
Encoding:
Assembly Source File  |  2001-12-15  |  2.3 KB  |  139 lines

  1. ;;
  2. ;; aPLib compression library  -  the smaller the better :)
  3. ;;
  4. ;; TASM / MASM / WASM fast assembler depacker
  5. ;;
  6. ;; Copyright (c) 1998-2000 by Joergen Ibsen / Jibz
  7. ;; All Rights Reserved
  8. ;;
  9.  
  10. .386p
  11. .MODEL flat
  12.  
  13. getbitM MACRO
  14. LOCAL stillbitsleft
  15.     add    dl, dl
  16.     jnz    stillbitsleft
  17.     mov    dl, [esi]
  18.     inc    esi
  19.     adc    dl, dl
  20. stillbitsleft:
  21. ENDM getbitM
  22.  
  23. domatchM MACRO reg
  24.     push   esi
  25.     mov    esi, edi
  26.     sub    esi, reg
  27.     rep    movsb
  28.     pop    esi
  29. ENDM domatchM
  30.  
  31. getgammaM MACRO reg
  32. LOCAL getmorebits
  33.     mov    reg, 1
  34. getmorebits:
  35.     getbitM
  36.     adc    reg, reg
  37.     getbitM
  38.     jc     getmorebits
  39. ENDM getgammaM
  40.  
  41. .CODE
  42.  
  43. PUBLIC _aP_depack_asm_fast
  44.  
  45. _aP_depack_asm_fast:
  46.     pushad
  47.  
  48.     mov    esi, [esp + 36]    ; C calling convention
  49.     mov    edi, [esp + 40]
  50.  
  51.     cld
  52.     mov    dl, 80h
  53.  
  54. literal:
  55.     mov     al, [esi]
  56.     inc     esi
  57.     mov     [edi], al
  58.     inc     edi
  59.  
  60. nexttag:
  61.     getbitM
  62.     jnc    literal
  63.  
  64.     getbitM
  65.     jnc    codepair
  66.  
  67.     xor    eax, eax
  68.     getbitM
  69.     jnc    shortmatch
  70.  
  71.     getbitM
  72.     adc    eax, eax
  73.     getbitM
  74.     adc    eax, eax
  75.     getbitM
  76.     adc    eax, eax
  77.     getbitM
  78.     adc    eax, eax
  79.     jz     thewrite
  80.     push   edi
  81.     sub    edi, eax
  82.     mov    al, [edi]
  83.     pop    edi
  84. thewrite:
  85.     mov    [edi], al
  86.     inc    edi
  87.     jmp    short nexttag
  88.  
  89. codepair:
  90.     getgammaM eax
  91.     sub    eax, 2
  92.     jnz    normalcodepair
  93.     getgammaM ecx
  94.     domatchM ebp
  95.     jmp    nexttag
  96.  
  97. normalcodepair:
  98.     dec    eax
  99.     shl    eax, 8
  100.     mov    al, [esi]
  101.     inc    esi
  102.     mov    ebp, eax
  103.     getgammaM ecx
  104.     cmp    eax, 32000
  105.     jae    do_add_2
  106.     cmp    eax, 1280
  107.     jb     not_gt_1280
  108.     inc    ecx
  109.     domatchM eax
  110.     jmp    nexttag
  111. not_gt_1280:
  112.     cmp    eax, 7fh
  113.     ja     dont_add_2
  114. do_add_2:
  115.     add    ecx, 2
  116. dont_add_2:
  117.     domatchM eax
  118.     jmp    nexttag
  119.  
  120. shortmatch:
  121.     mov    al, [esi]
  122.     inc    esi
  123.     xor    ecx, ecx
  124.     db     0c0h, 0e8h, 001h
  125.     jz     donedepacking
  126.     adc    ecx, 2
  127.     mov    ebp, eax
  128.     domatchM eax
  129.     jmp    nexttag
  130.  
  131. donedepacking:
  132.     sub    edi, [esp + 40]
  133.     mov    [esp + 28], edi    ; return unpacked length in eax
  134.  
  135.     popad
  136.     ret
  137.  
  138. END
  139.